/*
 * $Id: FilterCurrentClientAction.java 23 2002-09-29 13:59:30Z bpruessmann $
 *
 * Copyright (c) 2001 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.p4eclipse.internal.ui.views.submitted;

import net.sourceforge.p4eclipse.core.api.IChangesResult;
import net.sourceforge.p4eclipse.core.api.IInfoResult;
import net.sourceforge.p4eclipse.ui.PerforceUIPlugin;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.StructuredViewer;

/**
  * @version 	$Revision: 23 $
  * @author		<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class FilterCurrentClientAction extends Action
{
	private StructuredViewer parent;
	private ClientFilter filter = new ClientFilter();
	
	/** Helper method for creating instances of FilterCurrentUserAction. */
	public static final FilterCurrentClientAction newInstance(StructuredViewer parent, String text)
	{
		return new FilterCurrentClientAction(parent, text);
	}
	
	/** Constructor for FilterCurrentUserAction.
	  * @param text the text of the action.
	  */
	private FilterCurrentClientAction(StructuredViewer parent, String text)
	{
		super(text);
		this.parent = parent;
		
		this.parent.addFilter(filter);
		setChecked(false);
	}
	
	/** @see IAction#run() */
	public void run()
	{
		if (isChecked())
		{
			IInfoResult infoResult = PerforceUIPlugin.getClient().info();
			filter.setClientName(infoResult.getClientName()) ;
		}
		else
			filter.setClientName(null);

		parent.getControl().setRedraw(false);
		parent.refresh();
		parent.getControl().setRedraw(true);		
	}
}
